package com.zz.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveServer2Test {
    public static void main(String[] args) {

        String url = "jdbc:hive2://hadoop101:10000/default;" +
                "hive.server2.proxy.user=root;" +  // 指定代理用户
                "hive.server2.authentication=NOSASL";
        String user = "root";
        String password = "123456";

        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            Connection con = DriverManager.getConnection(url, user, password);
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SHOW DATABASES");

            System.out.println("连接成功，数据库列表:");
            while(rs.next()) {
                System.out.println(rs.getString(1));
            }

            con.close();
        } catch (Exception e) {
            System.err.println("连接失败: " + e.getMessage());
        }
    }
}